<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="root">
        <input type="text" @input='fn'>
        <ul>
            <li v-for="(value,index) in list" :key='value.id' v-if='value.condition'>
                {{index}}--{{value.name}}--{{value.age}}
            </li>
        </ul>
        <button @click='pintSequence'>年龄升序</button>
        <button @click='dropSequence'>年龄降序</button>
        <button @click='sequence'>原来排序</button>
    </div>

    <script src="../js/vue.js"></script>
    <script>
        new Vue({
            el: '#root',
            data: {
                list: [{
                        id: 1,
                        name: "tom",
                        age: 13,
                        condition: true,
                    },
                    {
                        id: 2,
                        name: 'jack',
                        age: 14,
                        condition: true,
                    },
                    {
                        id: 3,
                        name: 'jerry',
                        age: 17,
                        condition: true,
                    },
                    {
                        id: 4,
                        name: 'Mike',
                        age: 9,
                        condition: true,
                    },
                    {
                        id: 5,
                        name: 'jojo',
                        age: 19,
                        condition: true,
                    },
                    {
                        id: 6,
                        name: 'dio',
                        age: 39,
                        condition: true,
                    },
                    {
                        id: 7,
                        name: 'tony',
                        age: 29,
                        condition: true,
                    },
                    {
                        id: 8,
                        name: 'ph',
                        age: 49,
                        condition: true,
                    },
                ],
            },
            methods: {
                fn() {
                    let value = arguments[0].target.value.trim()
                    if (!value) {
                        this.list.forEach((item) => {
                            item.condition = true
                        })
                        return
                    }
                    //遍历数据对象
                    this.list.forEach((item) => {
                        if (item.name.indexOf(value) === -1) {
                            item.condition = false
                        }
                        //遍历item 将value数据进行判断
                    })
                },
                sequence() {
                    this.list.sort((item, nextitem) => {
                        return item.id - nextitem.id
                    })
                },
                pintSequence() {
                    this.list.sort((item, nextitem) => {
                        return item.age - nextitem.age
                    })
                },
                dropSequence() {
                    this.list.sort((item, nextitem) => {
                        return nextitem.age - item.age
                    })
                }
            }
        })
    </script>
</body>

</html>